import axios from 'axios';
import dataUrl from '@/config/env'
export const fetch =async (url:string,data:any,type="GET") =>{
  if(type !== 'GET'){
    return await axios.post(dataUrl+url,data)
  }else{
    if(data){
      let dataInfo="";
      for(const key in data){
        if(dataInfo===""){
          dataInfo+=`?${key}=${data[key]}`;
        }else{
          dataInfo+=`&${key}=${data[key]}`;
        }
      }
      return await axios.get(dataUrl+url+dataInfo);
    }else{
      return await axios.get(dataUrl+url);
    }
  }
}